import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/reset.css';
import * as Icons from '@ant-design/icons-vue';
import axios from 'axios';
import { Tool } from "@/utils/tool";

//获取环境配置的 请求前缀
axios.defaults.baseURL = process.env.VUE_APP_SERVER;

const app = createApp(App);
app.use(store).use(router).use(Antd).mount('#app');

//全局使用图标
const icons: any = Icons;
for (const i in icons) {
  app.component(i, icons[i]);
}

/*
* 使用axios拦截器打印请求和响应的数据
* */
axios.interceptors.request.use(function (config: any) {
  const token = store.state.user.token;
  if (Tool.isNotEmpty(token)) {
    config.headers.token = token;
  }
  return config;
}, error => {
  return Promise.reject(error);
});